using Microsoft.AspNetCore.Mvc;
using StudentManager.API.BLL;
using System.ComponentModel.DataAnnotations;
using WebApplication1.Test;

namespace WebApplication1.Controllers
{
    [ApiController]
    [Route("[controller]/[action]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };
        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
            Console.WriteLine("WeatherForecastController created.");
        }

        [HttpGet(Name = "GetWeatherForecast")]
        public IEnumerable<WeatherForecast> Test1()
        {
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
        }

        [HttpPost("{id}")]
        public IActionResult Test2(int id, int age, [FromBody] User user)
        {
            dynamic result = new {id=id, age=age,name=user.Name,password=user.Password};
            return Ok(Result.Data(result));
        }
    }

    public class User
    {
        [Required]
        public string Name { get; set; }
        [Required, MinLength(6)]
        public string Password { get; set; }
    }
}



